package com.br.unisal.library.business;



import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import com.br.unisal.library.exception.ArgumentValidator;
import com.br.unisal.library.exception.NullValueException;

public class Lending {
	private static final int MAXIMUM_LENDING_DAYS = 7;
	private Book book;
	private Date lendingDate;
	private Date returnDate;

	public Lending(Book book) throws IllegalArgumentException, NullValueException {
		ArgumentValidator.validateNullValue(book);
		this.book = book;
		setLendingInformations();
	}

	private void setLendingInformations() {
		setLendingDate();
		setReturnDate();
	}

	private void setReturnDate() {
		Calendar calendar = new GregorianCalendar(); 
		calendar.add(Calendar.DAY_OF_MONTH, MAXIMUM_LENDING_DAYS);
		returnDate = calendar.getTime();	
	}

	private void setLendingDate() {
		Calendar calendar = new GregorianCalendar(); 
		this.lendingDate = calendar.getTime();    
	}
	
	private String formatDate(Date date) {
		String format = "dd/MM/yyyy";  
		SimpleDateFormat formatedDate = new SimpleDateFormat(format);  
		return formatedDate.format(date);
	}
	
	public String getReturnDate() {
		return formatDate(returnDate);
	}
	
	public String getLendingDate() {
		return formatDate(lendingDate);
	}
	
	public Book getBook() {
		return this.book;
	}
}
